package com.jade.journal;

import java.util.Date;

import com.jade.framework.base.util.SimpleDate;
import com.jade.framework.base.util.SimpleTime;
import com.jade.journal.desc.JournalDesc;

/**
 * Journal事件
 *
 * @author Daisy
 * @version 1.0 14-9-21 下午8:32
 */
public class JournalEvent
{
    private String name;
    private Object item;
    private transient JournalLevel level = JournalLevel.INFO;

    private long time;

    /** 日志表结构描述，用于在写日志 */
    private transient JournalDesc desc;
    private SimpleDate simpleDate;
    private SimpleTime simpleTime;

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Object getItem()
    {
        return item;
    }

    public void setItem(Object item)
    {
        this.item = item;
    }

    /**
     * 根据键返回Item中的字段
     *
     * @param key 字段键
     * @return 如果存在该字段，返回该对象，否则返回<code>null</code>
     */
    public Object getField(String key)
    {
        //todo
        if (item == null) {
            return null;
        }
        return null;
    }

    /**
     * 根据索引返回Item中的字段
     *
     * @param index 字段索引
     * @return 如果存在该字段，返回该对象，否则返回<code>null</code>
     * @throws ArrayIndexOutOfBoundsException 如果指定的<code>index</code>非法
     */
    public Object getField(int index)
    {
        //todo
        if (item == null) {
            return null;
        }
        return null;
    }

    public long getTime()
    {
        return time;
    }

    public void setTime(long time)
    {
        this.time = time;
        this.simpleDate = new SimpleDate(time);
        this.simpleTime = new SimpleTime(time);
    }

    public void setTime(Date date)
    {
        if (date != null) {
            setTime(date.getTime());
        }
    }

    public SimpleDate getSimpleDate()
    {
        return simpleDate;
    }

    public SimpleTime getSimpleTime()
    {
        return simpleTime;
    }

    public JournalLevel getLevel()
    {
        return level;
    }

    public void setLevel(JournalLevel level)
    {
        this.level = level;
    }

    public JournalDesc getDesc()
    {
        return desc;
    }

    public void setDesc(JournalDesc desc)
    {
        this.desc = desc;
    }

    public String toString()
    {
        StringBuilder sb = new StringBuilder(64);
        sb.append("JournalEvent [");
        sb.append("name=").append(name).append(',');
        sb.append("level=").append(level).append(',');
        sb.append("time=").append(new Date(time)).append(',');
        sb.append("item=").append(item).append(']');
        return sb.toString();
    }

}